﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BrainTechLLC.Silverlight.Controls;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class EditAbility : BaseDataVisualizer, ISingleItemDataVisualizer
    {
        public override void SetVisualizedData(DataVisualizer vis, object o) { Ability = o as Ability; base.SetVisualizedData(vis, o); }
        public Type VisualizeType { get { return typeof(Ability); } }
        public string VisualizerName { get { return "EditAbility"; } }

        public static readonly DependencyProperty AbilityProperty = DependencyProperty.Register(
            "Ability", typeof(Ability), typeof(EditAbility), new PropertyMetadata(null, new PropertyChangedCallback(AbilityChanged)));

        public Ability Ability
        {
            get { return (Ability)GetValue(AbilityProperty); }
            set { SetValue(AbilityProperty, value); }
        }

        public static void HandleChange<T2>(DependencyObject d, DependencyPropertyChangedEventArgs e, Action<EditAbility, T2> action)
        {
            d.HandleChange<EditAbility, T2>(e, action, (t) => t.UpdateBindings());
        }

        private static void AbilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            HandleChange<Ability>(d, e, (t, val) => t.Ability = val);
        }

        public override void UpdateBindings()
        {
            if (Ability != null)
            {
                gridData.DataContext = Ability;
            }
        }

        public override string TitleText
        {
            get
            {
                return (Ability == null) ? string.Empty :
                    string.Format("Ability {0} ({1} Prop)", Ability.AbilityName, Ability.PropertiesCount);
            }
        }

        public EditAbility()
        {
            InitializeComponent();
        }

        public override void OnSaveData()
        {
            DataAccess.Client.StoreAbilityAsync(DataAccess.AssignedUniqueId, Ability);
        }

        private void ShowProps_Loaded(object sender, RoutedEventArgs e)
        {
            //editAbilityProperties.Window.Indent = Window.Indent + 1;         
        }
    }
}